﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Chisel.Core
{
    /// <summary>
    /// Represents an item (child) of an entity.
    /// </summary>
    public class Item : EntityChild
    {

        public Item(string label)
            : base(label)
        {
			_stackPanel = new StackPanel() {
				Orientation = Orientation.Horizontal,
				IsHitTestVisible = true
			};
			Content = _stackPanel;

            _stackPanel.Children.Add(_label);
        }

		/// <summary>
		/// The main layout for the item.
		/// </summary>
		private StackPanel _stackPanel;


		protected override void ResetStyle()
		{
			base.ResetStyle();

			_stackPanel.Background = GetBrush(BrushType.Background, State);
		}

		/// <summary>
		/// The group this item belongs to.
		/// </summary>
		public ItemGroup Group { get; set; }


		#region Selection

		protected override void SelectAction()
		{
			ParentCanvas.Actors.DeselectAll();
			if (Group == null)
			{
				Entity.Children.Select(this);
			}
			else // belongs to a group
			{
				Group.Items.DeselectAll();
				Group.Items.Select(this);
			}
		}

		protected override void DeselectAllAction()
		{
			if (Group == null)
				Entity.Children.DeselectAll();
			else
				Group.Items.DeselectAll();
		}

		#endregion

	}
}
